var arr=[{id:5,age:30},{id:6,age:21},{id:8,age:14},{id:3,age:10},{id:3,age:20}];
var compare = function (x, y,key) {//比较函数
	console.log(x.id)
    if (x.id < y.id) {
        return -1;
    } else if (x.id > y.id) {
        return 1;
    } else {
        return 0;
    }
}
console.log(arr.sort(compare));   